# 导入库
import tkinter as tk
from tkinter import ttk, simpledialog, filedialog

# 导入逻辑代码
from Logic import add_task, create_card, edit_task, delete_card

# 创建主窗口
def create_main_window():
    window = tk.Tk()
    window.title("To Do List")
    window.geometry("800x600")

    # 创建列和框架
    columns = ["To_Do", "In Progress", "Done"]
    frames = {}
    for col in columns:
        frame = tk.Frame(window, relief=tk.RAISED, borderwidth=1)
        frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
        frames[col] = frame
        label = tk.Label(frame, text=col, bg='lightblue', font=('Arial', 12, 'bold'))
        label.pack(fill=tk.X)

    # 创建添加任务按钮
    button = tk.Button(window, text="Create", command=create_card_dialog)
    button.pack()

    return window

# 创建添加任务的对话框
def create_card_dialog():
    dialog = tk.Toplevel(window)
    dialog.title("Create New Task")
    dialog.geometry("400x300")

    # 创建输入框
    task_name_var = tk.StringVar()
    priority_var = tk.StringVar()
    due_data_var = tk.StringVar()
    image_path_var = tk.StringVar()

    task_name_label = tk.Label(dialog, text="Task Name:")
    task_name_label.pack(pady=5)
    task_name_entry = tk.Entry(dialog, textvariable=task_name_var)
    task_name_entry.pack(pady=5)

    priority_label = tk.Label(dialog, text="Priority:")
    priority_label.pack(pady=5)
    priority_entry = tk.Entry(dialog, textvariable=priority_var)
    priority_entry.pack(pady=5)

    due_data_label = tk.Label(dialog, text="Due Date:")
    due_data_label.pack(pady=5)
    due_data_entry = tk.Entry(dialog, textvariable=due_data_var)
    due_data_entry.pack(pady=5)

    # 创建选择图片功能
    def select_image():
        filename = filedialog.askopenfilename(title="Select Image", filetypes=[("Image Files", "*.png;*.jpg;*.jpeg;*.gif")])
        if filename:
            image_path_var.set(filename)

    # 创建确认按钮
    confirm_button = tk.Button(dialog, text="Confirm", command=lambda: add_task(task_name_var.get(), priority_var.get(), due_data_var.get(), image_path_var.get(), dialog))
    confirm_button.pack(pady=10)

    # 创建选择图片按钮
    select_image_button = tk.Button(dialog, text="Select Image", command=select_image)
    select_image_button.pack(pady=5)

    return dialog

# 创建主窗口
window = create_main_window()
window.mainloop()